<?php


namespace Hlcreation\Services;
use Hlcreation\Basic\Helper;
use App\Exceptions\ApiException as HOException;
class CloudStoreServices
{
    /**
     * 调用接口地址
     */
    private static function  urlApi($api_name=''){

       return config('contract.domain_name.'.$api_name);
    }

    /**
     * 创建平台
     * @param unknown $arr
     * @return boolean
     */

    public static function  CreateStore($arr)
    {
       return self::DataProcessing(self::urlApi('url_create_api'),$arr);


    }


    /**
     * 修改平台
     * @param unknown $arr
     * @return boolean
     */
    public static function  UpdateStore($arr)
    {

      return self::DataProcessing(self::urlApi('url_create_api'),$arr);


    }


    /**
     * 删除平台
     */
    public  static  function  DelStore($arr){
         return self::DataProcessing(self::urlApi('url_del_api'),$arr);
    }


    /**
     * 禁用平台
     * @param unknown $arr
     */
    public static function  DisabledStore($arr){
        return self::DataProcessing(self::urlApi('url_disabled_api'),$arr);
    }


    /**
     * 配置开关
     */
    public  static function  ConfigStore($arr){
       return self::DataProcessing(self::urlApi('url_config_api'),$arr);
    }


    /**
     * 同步短信次数合同次数
     */
    public  static  function  synchroSmsContract($arr){

        return self::DataProcessing(self::urlApi('url_synchro_api'),$arr,$boole=false);
    }


    /**
     * 进入平台
     */
    public  static function EntryContract($arr) {
        return self::DataProcessing(self::urlApi('url_contract_api'),$arr,$boole=false);


    }


    /**
     * 设置短信次数合同次数
     */
    public  static  function  setSmsContract($arr){

        return self::DataProcessing(self::urlApi('url_updatenum_api'),$arr,$boole=false);
    }


    /**
     * 数据处理
     * @param unknown $url
     * @param unknown $arr
     * @throws HOException
     * @return boolean
     */
    private static function  DataProcessing($url,$arr,$boole=true){
        try {
            $arr_json= json_encode($arr);

            $arr_encode=base64_encode($arr_json);

            $data=Helper::httpPost($url,$arr_encode);

            if(isset($data['code'])){
                if($data['code']==200){
                    if($boole) return true;
                    else return $data;
                }else{
                    throw new HOException($data['msg']);
                }
            }else{
                throw new HOException('电子合同平台接口异常');
            }
        } catch (\Exception $e) {
            throw new HOException($e->getMessage());
        }
    }



}
